import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    uname:sessionStorage.getItem('name'),  //保存当前登录用户名
    head_photo:sessionStorage.getItem('head'), //保存当前头像
    login_state:sessionStorage.getItem('state'), //保存登录状态
    page:sessionStorage.getItem('page')  //当前页数
  },
  getters: {
  },
  mutations: {
     //state就是vuex.state  
     //newName是传递过来的用户名参数
     updateName(state,newName){
      state.uname=newName
      // 将username存入sessionStorage
      window.sessionStorage.setItem('name',newName)
     },

    // 头像
     upheadPhoto(state,newPhoto){
       state.head_photo=newPhoto
       // 将head_photo(头像)存入sessionStorage
       window.sessionStorage.setItem('head',newPhoto)
     },
    //登录状态
    uloginState(state,newState){
      state.login_state=newState
      // 将login_state(登录状态)存入sessionStorage
      window.sessionStorage.setItem('state',newState)
    },
    // 当前页数
    uPage(state,newState){
      state.page=newState
      // 将page(当前页数)存入sessionStorage
      window.sessionStorage.setItem('page',newState)
    }
  },
  actions: {
  },
  modules: {
  }
})
